/*登陆框*/
	
function updateTips( t ) {
	$(".validateTips").text( t ).addClass( "ui-state-highlight" );
	setTimeout(function() {
		$(".validateTips").removeClass( "ui-state-highlight", 1500 );
	}, 500 );
}

function checkLength( o, n, min, max ) {
	if ( o.val().length > max || o.val().length < min ) {
		o.addClass( "ui-state-error" );
		o.focus();
		updateTips( "请输入" + n +"." );
		return false;
	} else {
		return true;
	}
}

function checkRegexp( o, regexp, n ) {
	if ( !( regexp.test( o.val() ) ) ) {
		o.addClass( "ui-state-error" );
		updateTips( n );
		return false;
	} else {
		return true;
	}
}
function compare( o, e, n){
		if(o.val() != e.val()){
			e.addClass( "ui-state-error" );
			updateTips( n );
			return false;
		}else{
			return true;
		}
	}
function logins(){
	$( "#win-login" ).dialog({
			show: "blind",
			hide: "explode",
			modal: true,
			buttons: {
			"登陆": function() {	
				var table = $('#win-login>div.table');
				//var username = $.trim(table.find('input.name').val());
				//var password = $.trim(table.find('input.password').val());
				var bValid = true;
				var name = $( "#name" ),
					password = $( "#password" ),

					allFields = $( [] ).add( name ).add( password );

				allFields.removeClass( "ui-state-error" );
				bValid = bValid && checkLength( table.find('input.name'), "用户名", 1, 16 );
				bValid = bValid && checkLength( table.find('input.password'), "密码", 1, 16 );
				if ( bValid ) {
					$.post(ajaxurl, {
							action: 'user-login',
							'log': $.trim(table.find('input.name').val()),
							'pwd': $.trim(table.find('input.password').val())
						}).done(function(data) {
							var cache = data; 
							cache = JSON.parse(cache);
							//alert(cache.success)
							if (cache.success) {
								window.location.href=home_url+"member"
							} else {
								alert('用户名或密码错误。请验证后重新输入。');
							}
						}).fail(function() {
							alert('error::通信失败。请稍后重试。')
						})
				}
				return false;
			},
			"忘记密码": function() {
				$( this ).dialog( "close" );
			}
		} 

	});
}
function register(){
	$( "#win-register" ).dialog({
		show: "blind",
		hide: "explode",
		modal: true,
		buttons:{
			"注册":function(){
				var table = $('#win-register>div.table');
				//var username = $.trim(table.find('input.name').val());
				//var password = $.trim(table.find('input.password').val());
				var bValid = true;
				var r_name = $("#r_name"),
					email  = $("#email"),
					r_password = $("#r_password"),
					rs_password = $("#rs_password"),
					allFields = $( [] ).add( r_name ).add( email ).add( r_password ).add( rs_password );

				allFields.removeClass( "ui-state-error" );
				bValid = bValid && checkLength( table.find('input.r_name'), "用户名", 1, 16 );
				bValid = bValid && checkLength( table.find('input.email'), "邮箱地址", 6, 80 );
				bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "邮箱地址不正确" );
				bValid = bValid && checkLength( table.find('input.r_password'), "密码六位数以上", 6, 16 );
				bValid = bValid && checkLength( table.find('input.rs_password'), "密码六位数以上", 6, 16 );
				bValid = bValid && compare( table.find('input.r_password'),table.find('input.rs_password'), "两次密码不一样" );
				if ( bValid ) {
					$.post(ajaxurl, {
							action: 'user-register',
							'log': $.trim(table.find('input.r_name').val()),
							'email': $.trim(table.find('input.email').val()),
							'pwd': $.trim(table.find('input.rs_password').val())
						}).done(function(data) {
							var cache = data; 
							cache = JSON.parse(cache);
							//alert(cache.success)
							if (cache.success == "1") {
								alert("注册成功，请登录！");
								window.location.href=home_url
							} else {
								alert(cache.success);
								//window.location.href=home_url
							}
						}).fail(function() {
							alert('error::通信失败。请稍后重试。')
						})
				}
				return false;	
			  }
			}
	})
}

function buildop(btn, box, saveid) {
  var $box_btn = $(btn);
  var $box = $(box);
  $box_btn.click(function() {
    var index = $box_btn.index($(this));
    if (typeof(saveid) != "undefined") {
      ChatSaveSettings(saveid, index);
    }
    $box_btn.removeClass('on');
    $(this).addClass('on');
    $box.hide();
    $($box.get(index)).fadeIn(300);
  });
  var i = ChatGetSettings(saveid);
  if (i) {
    $($box_btn.get(i)).trigger("click");
  } else {
    if ($box_btn.length == 3) {
      $($box_btn.get(1)).trigger("click");
    } else {
      $($box_btn.get(0)).trigger("click");
    }
  }
}

function jbfuc(){
 $( "#dialog-form" ).dialog({
	height: 300,
	width: 550,
	buttons: {
                "提交": function() {	
					var n = $('#name').val();
					var j = $('#jburl').val();
					var c = $('#jbcontent').val();
					var p = $('#postid').val();					
					$.ajax(themeurl+"/inc/wp-report.php?rname=" + n + "&rurl=" + j + "&rcontent=" + c + "&postid=" + p, {
						success: function(data){
							if(data == 1)
							{
								alert('举报成功!');
								$('#dialog-form').dialog( "close" );
							}
							else{ 							
								alert('举报没有成功，请重新尝试，或联系管理员');
							}
						},
						error: function() { 
							alert('传送失败，请重新尝试，或联系管理员');
						}
					});
					return false;
				},
                "取消": function() {
                    $( this ).dialog( "close" );
                }
            } 
});
}
function ratingfuc(){
	
	var v = $('#rating').val();
	var u = $('#userid').val();
	var uu = $('#username').val();
	var p = $('#postid').val();
	$.ajax(themeurl+"/inc/wp-integration.php?rating=" + v + "&userid=" + u + "&username=" + uu + "&postid=" + p, {
	success: function(data){
		var str = data;
		var v = str.substr(-1);
		var vv = str.substr(0,str.length-v.length)
		if(v == 1){
		alert('评分成功');
		var d = new Date(),datas = '';
		datas += d.getFullYear()+'-';
		datas  += d.getMonth() + 1+'-';
		datas  += d.getDate()+' ';
		datas += d.getHours()+':'; 
		datas  += d.getMinutes()+':'; 
		datas+= d.getSeconds()+''; 
		var string = "<li>" + "<p class='name' title='评分时间："+datas+"'><a href='#'>"+uu+"</a></p>" + "<p class='f f5'>+5</p>"+"</li>";	
		$("ul.rat_list" ).append(string); 			
		$('#v_cscores').html('<span>'+vv+'</span>');
		}else{
			alert(data);
		}
	},
	error: function() { 
		alert('传送失败，请重新尝试，或联系管理员');
	}
	});
	return false;
}











